/*
 * @(#)SpringContextLoaderListener.java $version 2010. 8. 11
 *
 * Copyright 2007-2010 NHN Corp. All rights Reserved. 
 * NHN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.nhncorp.usf.core.servlet;


import javax.servlet.ServletContextEvent;

import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.nhncorp.lucy.common.container.SpringBeanFactory;


/**
 * {@link ContextLoaderListener} 확장.
 * {@link SpringBeanFactory} Life Cycle 을 관리한다.
 *
 * @author Web Platform Development Team
 */
public class SpringContextLoaderListener extends ContextLoaderListener {
	
	/**
	 * @see org.springframework.web.context.ContextLoaderListener#contextInitialized(javax.servlet.ServletContextEvent)
	 * @param servletContextEvent ServletContextEvent
	 */
	@Override
	public void contextInitialized(ServletContextEvent servletContextEvent) {
		super.contextInitialized(servletContextEvent);
		SpringBeanFactory.init(WebApplicationContextUtils.getRequiredWebApplicationContext(servletContextEvent.getServletContext()));
	}

	/**
	 * @see org.springframework.web.context.ContextLoaderListener#contextDestroyed(javax.servlet.ServletContextEvent)
	 * @param servletContextEvent ServletContextEvent
	 */
	@Override
	public void contextDestroyed(ServletContextEvent servletContextEvent) {
		super.contextDestroyed(servletContextEvent);
		SpringBeanFactory.clear();
	}
}
